package de.tub.bazinga.object.particle;

import java.util.ArrayList;
import java.util.List;

import processing.core.PApplet;
import processing.core.PVector;
import de.tub.bazinga.object.interf.Drawable;

public class ParticleSystem implements Drawable {

	private final List<Particle> particles;

	public ParticleSystem(PVector position, int numOfParticles,
			ParticleBehavior particleBehavior) {
		particles = new ArrayList<Particle>(numOfParticles);
		for (int i = 0; i < numOfParticles; ++i) {
			particles.add(new Particle(position, particleBehavior));
		}
	}

	public void update(PVector bodyPartPosition) {
		for (Particle particle : particles) {
			particle.update();
			if (!particle.isAlive()) {
				particle.reset(bodyPartPosition);
			}
		}
	}

	@Override
	public void draw(PApplet window) {
		for (Particle particle : particles) {
			particle.draw(window);
		}
	}

}
